<?php

Class PropertyEvaluationsController extends AppController {

    public $name = 'PropertyEvaluations';

    function edit($id) {
        $this->PropertyEvaluation->recursive = -1;
        if (empty($this->data)) {

            $this->data = $this->PropertyEvaluation->find('first', array('conditions' => array('PropertyEvaluation.id' => $id), 'fields' => array('PropertyEvaluation.concepto', 'PropertyEvaluation.calificacion', 'PropertyEvaluation.property_id', 'PropertyEvaluation.id')));
        } else {

            if ($this->PropertyEvaluation->save($this->data)) {
                $this->Session->setFlash('Registro editado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'PropertyEvaluations', 'action' => 'index', $this->data['PropertyEvaluation']['property_id']));
            } else {
                $this->Session->setFlash('Error editando datos');
            }
        }
    }

    function add($property_id) {
        
        $datos = array('PropertyEvaluation' => array(
                'property_id' => $property_id
                ));
         $this->PropertyEvaluation->create();
        if ($this->PropertyEvaluation->saveAll($datos)) {
            $this->Session->setFlash('Registro Adicionado correctamente', 'flash_custom');
            $this->redirect(array('controller' => 'PropertyEvaluations', 'action' => 'index', $property_id));
        }
    }

    function index($property_id) {
        $this->set('property_id', $property_id);
        $this->PropertyEvaluation->recursive = -1;
        $this->paginate = array('PropertyEvaluation' => array('maxLimit' => 500, 'limit' => 50, 'fields' => array('PropertyEvaluation.id', 'PropertyEvaluation.concepto', 'PropertyEvaluation.calificacion', 'PropertyEvaluation.id')));
        $this->set('PropertyEvaluations', $this->paginate(array('PropertyEvaluation.property_id' => $property_id)));
    }
    
    
    function delete($evaluation_id,$property_id) {
        if($this->PropertyEvaluation->delete($evaluation_id)){
            $this->PropertyEvaluation->PropertyRequirement->deleteAll(array('PropertyRequirement.property_evaluation_id'=>$evaluation_id) );
            $this->Session->setFlash('Registro borrado correctamente', 'flash_custom');
            $this->redirect(array('controller' => 'PropertyEvaluations', 'action' => 'index', $property_id));
        }
        
    }

}

?>